<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>更新</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/JQuery/jquery-3.2.1.min.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/layui/layui.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/common.js"></script>
</head>
<body>
	<form class="layui-form layui-form-pane" action="">
			<input type="hidden" name="id" value="${movie.id}">
			<div class="layui-form-item">
				<label class="layui-form-label">电影名称</label>
				<div class="layui-input-block">
					<input type="text" name="name"  required lay-verify="required" id="name" value="${movie.name}" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
		        <label class="layui-form-label">上架时间</label>
		        <div class="layui-input-block">
		            <input readonly id="onShelfDate" type="text" name="onShelfDate" placeholder="请选择上架日期" autocomplete="off" class="layui-input">
		        </div>
		    </div>
		    <div class="layui-form-item">
		        <label class="layui-form-label">下架时间</label>
		        <div class="layui-input-block">
		            <input readonly id="offShelfDate" type="text" name="offShelfDate" placeholder="请选择下架日期" autocomplete="off" class="layui-input">
		        </div>
		    </div>
			<div class="layui-form-item">
				<label class="layui-form-label">票价</label>
				<div class="layui-input-block">
					<input type="text" name="ticketPrice" required lay-verify="required" id="ticketPrice" value="${movie.ticketPrice}" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
				</div>
			</div>
		</form>

		<script>
			//Demo
			layui.use('form', function() {
				var form = layui.form;
				
				//监听提交
				form.on('submit(formDemo)', function(data) {
					var sendData = JSON.parse(JSON.stringify(data.field));		//封装JSON数据 解决中文乱码
					var url = '${pageContext.request.contextPath}/movie/movie';
					$.post(url,sendData,function(data){
						if('${movie.onShelfDate}' != ''){
							if(data == "true"){
								myLayer.successMsg("更新成功!");
							}else{
								myLayer.errorMsg("更新失败!");
							}
						}else{
							if(data == "true"){
								myLayer.successMsg("添加成功!");
							}else{
								myLayer.errorMsg("添加失败!");
							}
						}
						setTimeout(function(){
							var index = parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
							window.parent.location.reload();//刷新父页面
							parent.layer.close(index);//关闭弹出层
						},1000);
					});
					return false;
				});
			});
			$("#name").click(
				function(){
					$(this).val("");
				}
			);
			$("#name").blur(
				function(){
					if($(this).val() == "")
						$(this).val("${movie.name}");
				}
			);
			$("#ticketPrice").click(
				function(){
					$(this).val("");
				}
			);
			$("#ticketPrice").blur(
				function(){
					if($(this).val() == "")
						$(this).val("${movie.ticketPrice}");
				}
			);
		    layui.use(["laydate","form"],function(){
		        var laydate = layui.laydate;
		        var onShelfDate,offShelfDate;
		        if('${movie.onShelfDate}' == ''){
		        	onShelfDate = new Date();
		        }else{
		        	onShelfDate = parseDate('${movie.onShelfDate}');
		        }
		        if('${movie.offShelfDate}' == ''){
		        	offShelfDate = new Date();
		        }else{
		        	offShelfDate = parseDate('${movie.offShelfDate}');
		        }
		        //执行一个laydate实例
		        laydate.render({
		            elem: '#onShelfDate', //指定元素
		            format:'yyyy/MM/dd',
		            value: onShelfDate //默认值
		        });
		        laydate.render({
		            elem: '#offShelfDate', //指定元素
		            format:'yyyy/MM/dd',
		            value: offShelfDate //默认值
		        });
		    });
		</script>
</body>
</html>